<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

    protected function _initAutoLoader() {
        $autoloader = Zend_Loader_Autoloader::getInstance ();
        $autoloader->registerNamespace("Benservi");
        return $autoloader;
    }

    protected function _initViews() {
        $this->bootstrap('view');
        $view = $this->getResource('view');
        $view->doctype('XHTML1_TRANSITIONAL');
        Zend_Registry::set('view', $view);

        $view->headTitle()->setSeparator(' - ')->headTitle('Benservi - Sistema Interno');
        $view->headMeta()->appendHttpEquiv('Content-type', 'text/html;charset=utf-8')
                         ->appendName('author', 'Gustavo Meredyk')
                         ->appendName('reply-to', 'gustavo@meredyk.com.br')                         
                         ->appendName('copyright', 'Gustavo Meredyk - Copyright 2011')
                         ->appendName('description', 'Benservi - Sistema Interno')
                         ->appendName('robots', 'noindex,nofollow')
                         ->appendName('robots', 'noarchive');
    }

    protected function _initPlugins() {
        $bootstrap = $this->getApplication();
        if ($bootstrap instanceof Zend_Application) {
            $bootstrap = $this;
        }
        $bootstrap->bootstrap('FrontController');
        $front = $bootstrap->getResource('FrontController');

        $front->registerPlugin(new Benservi_Plugins_Layout());
        $front->registerPlugin(new Benservi_Plugins_CheckAuth());
    }

    protected function _initMetadataCache() {
        $frontendOptions = array('automatic_serialization' => true);
        $backendOptions = array('cache_dir' => APPLICATION_PATH . '/../cache');
        
        $cache = Zend_Cache::factory('Core','File',$frontendOptions,$backendOptions);
        Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
    }

    protected function _initZFDebug() {
        $zfdebugConfig = $this->getOption('zfdebug');
        if ($zfdebugConfig['enabled'] != 1) {
          return;
        }
        $autoloader = Zend_Loader_Autoloader::getInstance();
        $autoloader->registerNamespace('ZFDebug');
        $this->bootstrap('db');
        $db = $this->getPluginResource('db')->getDbAdapter();
        $options = array(
            'plugins' => array('Variables',
                'Database' => array('adapter' => array('standard' => $db)),
                'File' => array('basePath' => '/'),
                'Memory',
                'Time',
                'Registry',
                'Exception')
        );
        $debug = new ZFDebug_Controller_Plugin_Debug($options);
        $this->bootstrap('frontController');
        $frontController = $this->getResource('frontController');
        $frontController->registerPlugin($debug);
    }    
}